﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;//使用IO
using System.IO.Ports;
using System.Threading;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
//using System.Runtime.Serialization.Formatters.Binary;
using System.Net;//使用IPAddress
using System.Net.Sockets;



namespace LPNRTool//在LPNRTool 命名空间
{

    unsafe public partial class LPNRTool : Form
    {
      
        ParaSetForm parachildform = new ParaSetForm();
        SerialPort com = new SerialPort();//初始化
        WriteLog Trace = new WriteLog();

        LiveVedio live_vedio = new LiveVedio();


        udpc udptest = new udpc();

        Thread TimeThread;

        public static Socket client;

        public IntPtr CameraHandle = IntPtr.Zero;
        public IntPtr picturehWnd = IntPtr.Zero;
        public int InitHvBit = 0;
        public int CloseHvBit = 1;

        public string CameraIPAddress = "";
        public static string GetManchineIPAddress = "";

        public int softTriggerCount = 0;

        private const int WM_USER = 0x0400;
        public static int MY_MSG_BEGIN = WM_USER + 100;
        public static int MY_MSG_END = WM_USER + 101;
        public static int My_MSG_HANDLE = 0;

        public bool _isgetplate = false;
        public bool _isgetlive = true;
        public bool _isreleasedata = true;

        public string planetAll = "";

        public bool enablequadbit = false;//输出车头图
        public bool enabletheadbit = false;//输出1/4图
        public bool enableallbit = false;//禁止输出抓拍全图
        public bool _isrecudp = true;
        public bool _issendudp = false;

        public static LPNRTool mainLPNR;
   

        public static LiveVedio Live_Vedio_Form = new LiveVedio();

        public LPNRTool()
        {
            InitializeComponent();
            mainLPNR = this;

            try
            {
                this.BackgroundImage = imageList.Images[0];
            }
            catch (Exception ex)
            {
                throw new Exception("图片加载失败" + ex.Message.ToString());
            }
        }

        private void LPNRTool_Load(object sender, EventArgs e)//主窗口
        {
            this.Width = 1100;
            this.Height = 750;

            //showplatetotext = new showplate(showplatehandle);//定义委托跨线程访问textbox

            this.TimeThread = new Thread(new ThreadStart(this.ThreadProcSafe));
            this.TimeThread.Start();
            this.TimeThread.IsBackground = true;

            AddCamListToTprcomBox();
            //this.LivecheckBox.Checked = true;

        }

        // 将text更新的界面控件的委托类型
        public delegate void SetTextCallback(string text);

        /// <summary>
        /// 定义线程的主体方法 线程的主体方法
        /// </summary>
        private void ThreadProcSafe()
        {
            //在线程中更新UI（通过控件的.Invoke方法）
            while (true)
            {
                this.SetText("当前时间:" + DateTime.Now.ToString());
            }
        }

        /// <summary>
        /// 定义更新UI控件的方法 更新文本框内容的方法
        /// </summary>
        /// <param name="text"></param>
        private void SetText(string text)
        {
            if (this.SystemTimeLable.InvokeRequired)//如果调用控件的线程和创建创建控件的线程不是同一个则为True
            {
                SetTextCallback d = new SetTextCallback(SetText);
                this.SystemTimeLable.Invoke(d, new object[] { text });
            }
            else
            {
                this.SystemTimeLable.Text = text;
            }
        }


        public string Iplist = "";
        public string[] newIplist;
        public int newIpListLen = 0;
        /// <summary>
        /// 将CameraListTocombox
        /// </summary>
        public void AddCamListToTprcomBox()
        {
            Iplist = Trace.readIpList();//读取CameraList写入TprIpCombox
            if (Iplist != string.Empty)
            {
                newIplist = Iplist.Split(new string[] { "\n" }, StringSplitOptions.None);//None:含返回的数组中的空数组元素 newIplist[0]="\r\n"
                newIpListLen = newIplist.Length;
                for (int i = 1; i < newIpListLen; i++)
                {
                    this.TprIpcomboBox.Items.Add(newIplist[i]);
                }
            }
        }

        /// <summary>
        /// 判断camera text 是否等于list
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public bool judgeInIplist(string str)
        {
            bool issanme = false;
            for (int i = 0; i < newIpListLen; i++)
            {
                if (newIplist[i] == str)
                {
                    issanme = true;
                }
            }
            return issanme;
        }

        public bool online = false;
        public bool IsIdle = false;


        int callnum = 0;

        Int32 WJ_Handle = 0;
        /// <summary>
        /// LPNRTool设备初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LinkButton_Click(object sender, EventArgs e)
        {
            try
            {

                CameraIPAddress = TprIpcomboBox.Text.Trim();
                IPAddress ip;
                if (IPAddress.TryParse(CameraIPAddress, out ip))
                {

                    if (ConfigHelper.GetConnectionStringConfig("haslpnr") == "yes")
                    {
                        CameraHandle = LPNRProgram.LPNR_Init(CameraIPAddress);//初始化LPNRTool摄像机句柄

                        if (CameraHandle != IntPtr.Zero)
                        {
                            LPNRProgram.LPNR_SetWinMsg(CameraHandle, this.Handle, MY_MSG_BEGIN);//消息接收窗口
                        }

                        //Creat_CameraThread_Function();//回掉函数
                    }


                    if (ConfigHelper.GetConnectionStringConfig("hasWJ") == "yes") //WJdll
                    {
                        bool a = LPNRProgram.WJLS_DVR_Init();

                        Trace.WriteLogFile("WJ抓拍机初始化成功  " + a);

                        WJ_Handle = LPNRProgram.WJLS_DVR_Login(CameraIPAddress, 0, "root", "runwell");

                        Trace.WriteLogFile("WJ抓拍机Login" + WJ_Handle);

                        //if (LPNRProgram.LPNR_SetCallBack(CameraHandle, myDelegate)) //最好声明委托实例为static,防止垃圾回收器的回收 
                        if (LPNRProgram.WJLS_DVR_SetDVRMessCallBack(myDelegate, WJ_Handle)) //最好声明委托实例为static,防止垃圾回收器的回收 
                        {
                            Trace.WriteLogFile("WJ回调成功");
                        }

                        GetLiveDele();//显示实时视频

                        this.pictureBoxVideo.Width = 840;
                        this.pictureBoxVideo.Height = 540;

                        this.pictureBoxVideo.Location = new Point(16, 60);

                    }

                }

                else
                {
                    MessageBox.Show("IP地址格式错误", "IP检查出错", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

            }
            catch (Exception ex)
            {
                throw new Exception("初始化抓拍机失败" + ex.ToString());
            }
        }
        Thread Camera_One_CallBackThread;
        private void Creat_CameraThread_Function()
        {
            //System.Threading.ThreadStart m_updateThread = new System.Threading.ThreadStart(Camera_OneThread);
            //System.Threading.Thread schedulerThread = new System.Threading.Thread(m_updateThread);
            //schedulerThread.Start();  

            Camera_One_CallBackThread = new Thread(new ThreadStart(this.Camera_OneThread));
            //ThreadList.Add(Camera_One_CallBackThread);
            //Camera_One_CallBackThread.IsBackground = true;
            Camera_One_CallBackThread.Start();
        }

        public LPNRProgram.LPNRCallbackDelegate Camera_One_Delegate = new LPNRProgram.LPNRCallbackDelegate(Camera_One_CallbackFunc); //需要传入回调函数名 

        private void Camera_OneThread()
        {
            if (CameraHandle != IntPtr.Zero)
            {

                if (LPNRProgram.LPNR_SetCallBack(CameraHandle, Camera_One_Delegate))
                {
                    Trace.WriteLogFile("LPNR_1: 摄像机设置回调成功");
                }
            }
            else
            {
                Trace.WriteLogFile("LPNR_1:  摄像机初始化失败");
            }
        }


        public static void Camera_One_CallbackFunc(IntPtr h, int a)
        {
            try
            {
                Thread.Sleep(200);
                switch (a)
                {
                    case 0:
                        WriteLog.WriteLogstatic("Event code: " + 0);
                        break;
                    case 1:
                        WriteLog.WriteLogstatic("Event code: " + 1);
                        break;
                    case 2:
                        WriteLog.WriteLogstatic("Event code: " + 2);
                        break;
                    case 3:
                        WriteLog.WriteLogstatic("Event code: " + 3);
                        break;
                    case 4:
                        WriteLog.WriteLogstatic("Event code: " + 4);
                        break;
                    case 5:
                        WriteLog.WriteLogstatic("Event code: " + 5);
                        break;

                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteLogstatic("异常: " + ex.ToString());
            }
        }




        public LPNRProgram.CallbackDelegate myDelegate = new LPNRProgram.CallbackDelegate(CallbackFunc); //需要传入回调函数名  

        public static byte[] carinfo;

        public static int car_a = 0;
        //回调函数
        public static void CallbackFunc(int a, IntPtr h)
        {
            switch (a)
            {
                case 0:
                    WriteLog.WriteLogstatic("WJ Event code: " + a);
                   
                    WJLS_GetPlateNo();
                    WJLS_GetBigImage();
                    WJLS_GetBinaryImage();
                    WJLS_GetSmallImage();

                    StructDemo stAlarmInfo = new StructDemo();
                    stAlarmInfo = (StructDemo)Marshal.PtrToStructure(h, typeof(StructDemo));

                    LPNRTool.mainLPNR.planetAll = "";

                    LPNRTool.mainLPNR.planetAll = Encoding.Default.GetString(stAlarmInfo.sLicense, 0, stAlarmInfo.sLicense.Length).Trim();
                    WriteLog.WriteLogstatic("车牌识别结果:" + "-----------------" + LPNRTool.mainLPNR.planetAll);
                    break;
            }
        }

      
        [StructLayout(LayoutKind.Sequential)]
        public struct StructDemo
        {
            public byte byDriveChan;    //触发车道号,默认为0

            public UInt32 dwPicLen;        //图片长度(近景图)

            public UInt32 dwPicPlateLen;  //车牌小图片长度（车牌彩图）

            public UInt32 dwBinPicLen;    //车牌二值图长度

            public IntPtr pBuffer1;      // 近景图

            public IntPtr pBuffer2;      // 车牌彩图

            public IntPtr pBuffer3;      //车牌二值图

          
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
            public byte[] sLicense; //车牌信息，颜色+车牌，无结果时，值为“未检测”

        }
      

        //获取大图
        public static void WJLS_GetBigImage()
        {
            int len = 1024 * 200;
            int Image_len = 0;
            byte[] Imagebuf = new byte[len];
            int ImageRef = 0;

            ImageRef = LPNRProgram.WJLS_DVR_GetBigImage(Imagebuf, len, ref Image_len);

            if (ImageRef == 0)
            {
                WriteLog.WriteLogstatic("WJ ImageRef: " + ImageRef + "WJ Image_len: " + Image_len + "WJ Imagebuf: " + Imagebuf.Length);

                GetBigImageDele(Imagebuf);
            }
        }

        //委托获取大图
        public delegate void GetBigImageCallback(byte[] str);
        public static void GetBigImageDele(byte[] str)
        {
            if (LPNRTool.mainLPNR.pictureBoxImage.InvokeRequired)
            {
                GetBigImageCallback d = new GetBigImageCallback(GetBigImageDele);
                LPNRTool.mainLPNR.pictureBoxImage.Invoke(d, new object[] { str });
            }
            else
            {
                Common.showpicture(840, 540, 16, 60, LPNRTool.mainLPNR.pictureBoxImage, str);
            }
        }

        //获取二值图
        public static void WJLS_GetBinaryImage()
        {
            int len = 1024 * 2;
            int Image_len = 0;
            byte[] Imagebuf = new byte[len];
            int ImageRef = 0;

            ImageRef = LPNRProgram.WJLS_DVR_GetBinaryImage(Imagebuf, len, ref Image_len);

            if (ImageRef == 0)
            {
                WriteLog.WriteLogstatic("WJ BinaryImage: " + ImageRef + "WJ BinaryImage_len: " + Image_len);

                GetBinaryImageDele(Imagebuf);
            }
        }
        //委托二值图
        public delegate void GetBinaryImageCallback(byte[] str);
        public static void GetBinaryImageDele(byte[] str)
        {
            if (LPNRTool.mainLPNR.BinarypictureBox.InvokeRequired)
            {
                GetBinaryImageCallback d = new GetBinaryImageCallback(GetBinaryImageDele);
                LPNRTool.mainLPNR.BinarypictureBox.Invoke(d, new object[] { str });
            }
            else
            {
                if (str != null & str.Length != 0 & str[0] != 0)
                {
                    Common.showpicture(LPNRTool.mainLPNR.BinarypictureBox.Width, LPNRTool.mainLPNR.BinarypictureBox.Height,
                                        LPNRTool.mainLPNR.BinarypictureBox.Location.X, LPNRTool.mainLPNR.BinarypictureBox.Location.Y,
                                        LPNRTool.mainLPNR.BinarypictureBox, str);
                }
            }
        }

        //获取彩图
        public static void WJLS_GetSmallImage()
        {
            int len = 1024 * 40;
            int Image_len = 0;
            byte[] Imagebuf = new byte[len];
            int ImageRef = 0;

            ImageRef = LPNRProgram.WJLS_DVR_GetSmallImage(Imagebuf, len, ref Image_len);

            if (ImageRef == 0)
            {
                WriteLog.WriteLogstatic("WJ SmallImage: " + ImageRef + "WJ SmallImage_len: " + Image_len);

                GetSmallImageDele(Imagebuf);
            }
        }

        //委托彩图
        public delegate void GetSmallImageCallback(byte[] str);
        public static void GetSmallImageDele(byte[] str)
        {
            if (LPNRTool.mainLPNR.ColorpictureBox.InvokeRequired)
            {
                GetSmallImageCallback d = new GetSmallImageCallback(GetSmallImageDele);
                LPNRTool.mainLPNR.ColorpictureBox.Invoke(d, new object[] { str });
            }
            else
            {
                if (str != null & str.Length != 0 & str[0] != 0)
                {
                    Common.showpicture(LPNRTool.mainLPNR.ColorpictureBox.Width, LPNRTool.mainLPNR.ColorpictureBox.Height,
                                        LPNRTool.mainLPNR.ColorpictureBox.Location.X, LPNRTool.mainLPNR.ColorpictureBox.Location.Y,
                                        LPNRTool.mainLPNR.ColorpictureBox, str);
                }
            }
        }

        //获取车牌号码
        public static void WJLS_GetPlateNo()
        {
            string planetAll = "";
            int len = 12;
            int Image_len = 0;
            byte[] Imagebuf = new byte[len];
            int ImageRef = 0;

            LPNRProgram.WJLS_DVR_GetPlateNo(Imagebuf, len, ref Image_len);

            planetAll = Encoding.Default.GetString(Imagebuf, 0, Imagebuf.Length).Trim(('\0'));
            WriteLog.WriteLogstatic("WJ PlateNo: " + planetAll + "WJ PlateNo_len: " + Image_len);
            if (planetAll != string.Empty)
            {
                GetPlateNoDele(planetAll);//处理车牌至textbox显示
            }
        }
        //委托显示车牌号码
        public delegate void GetPlateNoCallback(string str);
        public static void GetPlateNoDele(string str)
        {
            if (LPNRTool.mainLPNR.PlateText.InvokeRequired)
            {
                GetPlateNoCallback d = new GetPlateNoCallback(GetPlateNoDele);
                LPNRTool.mainLPNR.PlateText.Invoke(d, new object[] { str });
            }
            else
            {
                LPNRTool.mainLPNR.PlateText.Text = str;
            }
        }


        //获取实时视频
        public delegate void GetLiveCallback();
        public static void GetLiveDele()
        {
            if (LPNRTool.mainLPNR.pictureBoxVideo.InvokeRequired)
            {
                GetLiveCallback d = new GetLiveCallback(GetLiveDele);
                LPNRTool.mainLPNR.pictureBoxVideo.Invoke(d, new object[] { });
            }
            else
            {
                Int32 RealRef = 0;
            
                RealRef = LPNRProgram.WJLS_DVR_RealPlay(LPNRTool.mainLPNR.WJ_Handle, LPNRTool.mainLPNR.pictureBoxVideo.Handle);
                WriteLog.WriteLogstatic("实时图像 获取的返回值 RealRef: " + RealRef);

            }
        }


        /// <summary>
        /// 判断摄像机是否在线
        /// </summary>
        public void judgeonline()
        {
            online = LPNRProgram.LPNR_IsOnline(CameraHandle);
            IsIdle = LPNRProgram.LPNR_IsIdle(CameraHandle);

            this.pictureBoxVideo.Visible = true;
            this.HeadpictureBox.Visible = false;
            this.QuadpictureBox.Visible = false;
            this.pictureBoxImage.Visible = false;

            try
            {
                _isresetlinkbit = false;
                while (_isresetlinkbit == false)
                {
                    if (online == true)
                    {
                        getMachineIp();//获取车牌ip

                        Trace.WriteLogFile("事件编号1：LPNR连线");
                        Trace.WriteLogFile("LPNRTool online is " + online);
                        Trace.WriteLogFile("抓拍机是否在识别中" + IsIdle);
                        LinkButton.Enabled = false;
                        CloseButton.Enabled = true;
                        Trace.WriteLogFile("摄像机初始化完成！");
                        if (judgeInIplist(CameraIPAddress) == false)
                        {
                            Trace.writeIpList(CameraIPAddress);//写入CamreaList
                        }
                        _isresetlinkbit = false;
                        break;
                    }
                    else
                    {
                        CameraHandle = LPNRProgram.LPNR_Init(CameraIPAddress);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }


        /// <summary>
        /// 自动重连
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ResetLinkbutton_Click(object sender, EventArgs e)
        {

            ThreadStart restlinkthread = new ThreadStart(relink);
            Thread link = new Thread(restlinkthread);
            link.Start();
        }
        public bool _isresetlinkbit = false;
        public void relink()
        {
            while (_isresetlinkbit == false)
            {
                Trace.WriteLogFile("relink online is " + online.ToString());
                if (online == true)
                {
                    _isresetlinkbit = true;
                    // break;
                }
                else
                {
                    CameraHandle = LPNRProgram.LPNR_Init(CameraIPAddress);//初始化LPNRTool摄像机句柄
                    break;
                }
            }
        }

        public int i = 1;
        //拦截并处理系统消息和自定义消息
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == MY_MSG_BEGIN)
            {
                switch (int.Parse(m.LParam.ToString()))
                {
                    case 1: My_MSG_HANDLE = 1;
                        judgeonline();//判断是否online
                        break;
                    case 2: My_MSG_HANDLE = 2; Trace.WriteLogFile("事件编号2：LPNR离线"); break;
                    case 3: My_MSG_HANDLE = 3;
                        Trace.WriteLogFile("事件编号3：开始进行识别处理");
                        break;
                    case 4: My_MSG_HANDLE = 4;
                        Trace.WriteLogFile("事件编号4：识别处理结束可以获取结果。（上位机要等收到事件编号4后才可以去获取车牌信息和图片）");
                        //ThreadStart GetPlateThreadStart = new ThreadStart(GetPlateFunction);
                        //GetPlateNumberThread = new Thread(GetPlateThreadStart);
                        //Trace.WriteLogFile("获取车牌号码线程开启");
                        //GetPlateNumberThread.Start();//获取车牌号
                        GetPlateFunction();//获取车牌号 
                        getPlateAttribute();//获取额外信息
                        getplatecolorFunction();//获取彩色图
                        getplatBinaryFunction();//获取二值化
                        //GetTiming();//获取处理时间
                        showinfo();//显示处理时间
                        getimageFunction();//获取抓拍图片
                        getheadimageFunction();//获取车头图
                        getquadimageFunction();//获取1/4图
                        _isreleasedata = LPNRProgram.LPNR_ReleaseData(CameraHandle);//释放当前识别结果动态分配的数据
                        break;
                    case 5: My_MSG_HANDLE = 5;
                        if (CameraHandle != IntPtr.Zero)
                        {
                            i++;
                            if (i % 2 == 0)
                            {
                                this.Invoke(new InvokeDelegate(GetLiveVideo));
                                
                                if (i == 2147483646)
                                {
                                    i = 0;
                                }
                                //GetLiveVideo();
                                //Trace.WriteLogFile("事件编号5：实时图像帧更新，可以获取，更新画面。");
                            }
                        }
                        break;
                    case 6: My_MSG_HANDLE = 6; Trace.WriteLogFile("事件编号6：车辆进入虚拟线圈检测区"); break;
                    case 7: My_MSG_HANDLE = 7; Trace.WriteLogFile("事件编号7：车辆离开虚拟线圈检测区"); break;
                    case 8: My_MSG_HANDLE = 8; Trace.WriteLogFile("事件编号8：扩展DI点状态有变化（一体机才有扩展DI）"); break;
                    default:
                        break;
                };
            }
            else if (m.Msg == MY_MSG_END)
            {
                Trace.WriteLogFile("类Demo for循环结束.");
            }
            base.WndProc(ref m);
        }

        /// <summary>
        /// 获取抓拍机IP号
        /// </summary>
        public void getMachineIp()
        {
            byte[] ip = new byte[CameraIPAddress.Length];
            LPNRProgram.LPNR_GetMachineIP(CameraHandle, ip);
            GetManchineIPAddress = Encoding.Default.GetString(ip, 0, ip.Length);
            Trace.WriteLogFile("获取到设备IP" + GetManchineIPAddress);
        }

        /// <summary>
        /// 显示处理时间 车牌额外信息
        /// </summary>
        public void showinfo()
        {
            string a = GetTiming();
            string b = getPlateAttribute();
            string c = a + b;
            this.GetTimingtext.ForeColor = Color.Blue;
            this.GetTimingtext.Text = c;
        }

        /// <summary>
        /// 获取处理时间
        /// </summary>
        public string GetTiming()
        {
            int processtime = 0;
            int handletime = 0;
            LPNRProgram.LPNR_GetTiming(CameraHandle, ref processtime, ref handletime);
            Trace.WriteLogFile("总过程时间:" + processtime + "ms" + "  " + "总处理时间:" + handletime + "ms");

            return "总过程时间:" + processtime + "ms" + "\r\n" + "总处理时间:" + handletime + "ms" + "\r\n";
        }

        /// <summary>
        /// 获取车牌额外的信息
        /// </summary>
        public string getPlateAttribute()
        {
            byte[] plateattr = new byte[8];
            LPNRProgram.LPNR_GetPlateAttribute(CameraHandle, plateattr);
            string confidencestr = plateattr[0].ToString();//可信度
            string headortailstr = plateattr[1].ToString();//车头或是车尾的车牌 1：车头，0xff 车尾，0 未知
            string carcolorstr = plateattr[2].ToString();//车身颜色码
            string carspeedstr = plateattr[3].ToString();//车速
            string triggersourcestr = plateattr[4].ToString();//触发源 (0：图片返送，1：上位机触发，2：线圈触发，3：定时触发，4：虚拟线圈触发，5：超速触发)

            string platedirection = "";
            string speed = "";
            string trigger = "";

            if (confidencestr != "0")
            {
                this.confidenceText.Text = confidencestr + "%";
            }
            else
            {
                this.confidenceText.Text = "";
            }

            if (carspeedstr != "0")
            {
                speed = carspeedstr;
            }
            else
            {
                speed = "";
            }
            switch (headortailstr)
            {
                case "1": platedirection = "车头"; break;
                case "0xff": platedirection = "车尾"; break;
                case "0": platedirection = "未知"; break;
                default: break;
            }

            switch (triggersourcestr)
            {
                case "0": trigger = "图片返送"; break;
                case "1": trigger = "上位机触发"; break;
                case "2": trigger = "线圈触发"; break;
                case "3": trigger = "定时触发"; break;
                //case "4": trigger = "虚拟线圈触发"; break;
                case "4": trigger = "视频触发"; break;
                case "5": trigger = "超速触发"; break;
                default: break;
            }
            return "====================" + "\r\n" + "触发方式:" + trigger + "\r\n" + "车牌位置:" + platedirection;
        }

        /// <summary>
        /// 获取车牌号方法
        /// </summary>
        public void GetPlateFunction()
        {
            try
            {
                //_isgetplate = false;
                //while (_isgetplate == false)
                //{
                byte[] plante = new byte[12];

                LPNRProgram.LPNR_Lock(CameraHandle);//上锁
                LPNRProgram.LPNR_GetPlateNumber(CameraHandle, plante);

                planetAll = Encoding.Default.GetString(plante, 0, plante.Length).Trim(('\0'));
                Trace.WriteLogFile("车牌识别结果:" + "-----------------" + planetAll);
                if (planetAll != string.Empty)
                {
                    showplatehandle(planetAll);//处理车牌至textbox显示

                    LPNRProgram.LPNR_Unlock(CameraHandle);//解锁
                }
                else
                {
                    LPNRProgram.LPNR_Unlock(CameraHandle);//解锁
                    Trace.WriteLogFile("车牌识别结果为null" + "-----------------");
                }
                _isgetplate = true;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 跨线程访问主窗体的platetextbox控件
        /// </summary>
        /// <param name="info"></param>
        //private delegate void showplate(string info);
        //showplate showplatetotext;

        ParkLock.LockMain newlock = new ParkLock.LockMain();

        public void showplatehandle(string info)
        {
            //if (this.InvokeRequired)
            //{
            //    this.Invoke(showplatetotext, info);
            //    return;
            //}
            string plantecolor = info.Substring(0, 1);
            string planetNo = info.Remove(0, 1);
            Trace.WriteLogFile("解析后车牌颜色：" + plantecolor + "  " + "车牌：" + planetNo);

            switch (plantecolor)
            {
                case "黄":
                    this.PlateText.Text = planetNo;
                    this.PlateText.BackColor = Color.Yellow;
                    this.PlateText.ForeColor = Color.Black;
                    //this.PlateText.TextAlign = HorizontalAlignment.Center;
                    break;
                case "蓝":
                    this.PlateText.BackColor = Color.Blue;
                    this.PlateText.ForeColor = Color.White;
                    this.PlateText.Text = planetNo;

                    if (planetNo == "苏E38NK6")
                    {
                        newlock.FallParkLock();//得到车牌后操作车位锁
                    }
                    break;
                case "白":
                    this.PlateText.BackColor = Color.White;
                    this.PlateText.ForeColor = Color.Black;
                    this.PlateText.Text = planetNo;
                    break;
                case "绿":
                    this.PlateText.BackColor = Color.PaleGreen;
                    this.PlateText.ForeColor = Color.Black;
                    this.PlateText.Text = planetNo;
                    break;
                case "黑":
                    this.PlateText.BackColor = Color.Black;
                    this.PlateText.ForeColor = Color.White;
                    this.PlateText.Text = planetNo;
                    break;
                default:
                    this.PlateText.BackColor = Color.Red;
                    this.PlateText.ForeColor = Color.White;
                    this.PlateText.Text = "无车牌";
                    break;
            }
        }


        private delegate void InvokeDelegate();
        /// <summary>
        /// 获取实时视频
        /// </summary>
        public void GetLiveVideo()
        {
            try
            {
                if (LivecheckBox.Checked == true)
                {
                    int GetLiveFrame = 0;
                    //LPNRProgram.LPNR_Lock(CameraHandle);//上锁
                    int size = LPNRProgram.LPNR_GetLiveFrameSize(CameraHandle);
                    if (size != 0)
                    {
                        byte[] Livebuf = new byte[size];
                        GetLiveFrame = LPNRProgram.LPNR_GetLiveFrame(CameraHandle, Livebuf);
                        if (GetLiveFrame != size)
                        {
                            //LPNRProgram.LPNR_Unlock(CameraHandle);//解锁
                        }
                        else
                        {
                            Trace.WriteLogFile("LPNR_GetLiveFrame获取实时返回值" + GetLiveFrame);
                            showVideoToPicture(Livebuf);
                            //GuiShowImage(Livebuf);//show image To picture
                            // LPNRProgram.LPNR_Unlock(CameraHandle);//解锁
                        }
                    }
                    else
                    {
                        // LPNRProgram.LPNR_Unlock(CameraHandle);//解锁
                    }
                }

            }
            catch (Exception ex)
            {
                throw new Exception("内存操作失败:" + ex.ToString());
            }
        }
        /// <summary>
        /// 获取抓拍图片
        /// </summary>
        public void getimageFunction()
        {
            int GetCapturedImageSize = 0;
            try
            {
                LPNRProgram.LPNR_Lock(CameraHandle);//上锁
                int len = LPNRProgram.LPNR_GetCapturedImageSize(CameraHandle);//获取抓拍图片大小

                if (len != 0)
                {
                    Trace.WriteLogFile("获取抓拍图片大小" + len.ToString());

                    byte[] Imagebuf = new byte[len];

                    LPNRProgram.LPNR_Lock(CameraHandle);//上锁
                    GetCapturedImageSize = LPNRProgram.LPNR_GetCapturedImage(CameraHandle, Imagebuf);
                    if (GetCapturedImageSize != 0)
                    {
                        Trace.WriteLogFile("GetCapturedImageSize获取图片返回值" + GetCapturedImageSize.ToString());
                        LPNRProgram.LPNR_Unlock(CameraHandle);//解锁

                        Trace.WriteLogFile("Imagebuf大小" + Imagebuf.Length.ToString());
                        showImageToPicture(Imagebuf);//show image To picture
                    }
                }
                else
                {
                    Trace.WriteLogFile("图片大小获取失败");
                }
                LPNRProgram.LPNR_Unlock(CameraHandle);//解锁
            }
            catch (Exception ex)
            {
                throw new Exception("内存操作失败:" + ex.ToString());
            }
        }
        /// <summary>
        /// 获取彩色图
        /// </summary>
        public void getplatecolorFunction()
        {
            try
            {
                LPNRProgram.LPNR_Lock(CameraHandle);
                int colorsize = LPNRProgram.LPNR_GetPlateColorImageSize(CameraHandle);
                Trace.WriteLogFile("colorsize" + colorsize.ToString());
                if (colorsize != 0)
                {
                    byte[] buf = new byte[colorsize];
                    int GetPlateColorImagesize = LPNRProgram.LPNR_GetPlateColorImage(CameraHandle, buf);
                    if (GetPlateColorImagesize != colorsize)
                    {
                        LPNRProgram.LPNR_Unlock(CameraHandle);
                    }
                    else
                    {
                        Trace.WriteLogFile("获取彩图图片大小" + colorsize.ToString());
                        Common.showpicture(this.ColorpictureBox.Width, this.ColorpictureBox.Height, this.ColorpictureBox.Location.X, this.ColorpictureBox.Location.Y, this.ColorpictureBox, buf);

                        LPNRProgram.LPNR_Unlock(CameraHandle);
                        string pic = "vcolor" + DateTime.Now.ToString("HHmmss") + ".bmp";
                        Trace.WriteLogFile(pic);
                    }
                }
                else
                {
                    LPNRProgram.LPNR_Unlock(CameraHandle);
                    this.ColorpictureBox.Image = null;
                    Trace.WriteLogFile("无彩色图");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }


        /// <summary>
        /// 获取二值图
        /// </summary>
        public void getplatBinaryFunction()
        {
            try
            {
                LPNRProgram.LPNR_Lock(CameraHandle);
                int Binarysize = LPNRProgram.LPNR_GetPlateBinaryImageSize(CameraHandle);
                Trace.WriteLogFile("Binarysize" + Binarysize.ToString());
                if (Binarysize != 0)
                {
                    byte[] buf = new byte[Binarysize];
                    int a = LPNRProgram.LPNR_GetPlateBinaryImage(CameraHandle, buf);
                    if (a != Binarysize)
                    {
                        LPNRProgram.LPNR_Unlock(CameraHandle);
                    }
                    else
                    {
                        Trace.WriteLogFile("获取二值图图片大小" + Binarysize.ToString());
                        Common.showpicture(this.BinarypictureBox.Width, this.BinarypictureBox.Height, this.BinarypictureBox.Location.X, this.BinarypictureBox.Location.Y, this.BinarypictureBox, buf);
                        LPNRProgram.LPNR_Unlock(CameraHandle);
                        string pic = "vbinary" + DateTime.Now.ToString("HHmmss") + ".bmp";
                        Trace.WriteLogFile(pic);
                    }
                }
                else
                {
                    LPNRProgram.LPNR_Unlock(CameraHandle);
                    this.BinarypictureBox.Image = null;
                    Trace.WriteLogFile("无二值化图 ");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }


        /// <summary>
        /// 获取车头图
        /// </summary>
        public void getheadimageFunction()
        {
            try
            {
                int GetHeadImageSize = 0;
                LPNRProgram.LPNR_Lock(CameraHandle);//上锁
                int len = LPNRProgram.LPNR_GetHeadImageSize(CameraHandle);//获取车头图图片大小
                LPNRProgram.LPNR_Unlock(CameraHandle);//解锁
                Trace.WriteLogFile("获取车头图片大小" + len.ToString());

                if (len != 0)
                {
                    byte[] Imagebuf = new byte[len];

                    LPNRProgram.LPNR_Lock(CameraHandle);//上锁
                    GetHeadImageSize = LPNRProgram.LPNR_GetHeadImage(CameraHandle, Imagebuf);
                    if (GetHeadImageSize != 0)
                    {
                        Trace.WriteLogFile("LPNR_GetHeadImage获取车头图图片返回值" + GetHeadImageSize.ToString());
                        LPNRProgram.LPNR_Unlock(CameraHandle);//解锁

                        Trace.WriteLogFile("Imagebuf大小" + Imagebuf.Length.ToString());
                        showheadImageToPicture(Imagebuf);//show image To picture
                    }
                }
                else
                {
                    Trace.WriteLogFile("车头图功能未使能");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("内存操作失败:" + ex.ToString());
            }
        }

        /// <summary>
        /// 显示车头图至picture
        /// </summary>
        /// <param name="buf"></param>
        public void showheadImageToPicture(byte[] buf)
        {
            Common.showpicture(840, 540, 16, 60, this.HeadpictureBox, buf);

            if (planetAll != string.Empty)
            {
                string plantecolor = planetAll.Substring(0, 1);
                if (plantecolor != "蓝" && plantecolor != "黄" && plantecolor != "绿" && plantecolor != "黑" && plantecolor != "白")
                {
                    planetAll = "无车牌";
                }
                string pic = "vhead" + DateTime.Now.ToString("HHmmss") + "(" + planetAll + ")" + ".jpg";
                Trace.WriteLogFile(pic);
                Common.SaveTriggerPicture(pic, buf);//保存图片至windows目录中
            }
        }

        /// <summary>
        /// 获取1/4图
        /// </summary>
        public void getquadimageFunction()
        {
            try
            {
                int GetQuadImageSize = 0;
                LPNRProgram.LPNR_Lock(CameraHandle);//上锁
                int len = LPNRProgram.LPNR_GetQuadImageSize(CameraHandle);//获取车头图图片大小
                LPNRProgram.LPNR_Unlock(CameraHandle);//解锁
                Trace.WriteLogFile("获取1/4图片大小" + len.ToString());

                if (len != 0)
                {
                    byte[] Imagebuf = new byte[len];

                    LPNRProgram.LPNR_Lock(CameraHandle);//上锁
                    GetQuadImageSize = LPNRProgram.LPNR_GetQuadImage(CameraHandle, Imagebuf);
                    if (GetQuadImageSize != 0)
                    {
                        Trace.WriteLogFile("LPNR_GetHeadImage获取1/4图片返回值" + GetQuadImageSize.ToString());
                        LPNRProgram.LPNR_Unlock(CameraHandle);//解锁

                        Trace.WriteLogFile("Imagebuf大小" + Imagebuf.Length.ToString());
                        showquadImageToPicture(Imagebuf);//show image To picture
                    }
                }
                else
                {
                    Trace.WriteLogFile("1/4图片功能未使能" + "\r\n");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("内存操作失败:" + ex.ToString());
            }
        }
        /// <summary>
        /// 显示1/4图至picture
        /// </summary>
        /// <param name="buf"></param>
        public void showquadImageToPicture(byte[] buf)
        {
            Common.showpicture(840, 540, 16, 60, this.QuadpictureBox, buf);

            string plantecolor = planetAll.Substring(0, 1);
            if (plantecolor != "蓝" && plantecolor != "黄" && plantecolor != "绿" && plantecolor != "黑" && plantecolor != "白")
            {
                planetAll = "无车牌";
            }
            string pic = "vquad" + DateTime.Now.ToString("HHmmss") + "(" + planetAll + ")" + ".jpg";
            Trace.WriteLogFile(pic);
            Common.SaveTriggerPicture(pic, buf);//保存图片至windows目录中
        }

        /// <summary>
        /// Video至Tpicturebox显示
        /// </summary>
        /// <param name="buf"></param>
        public bool doublebit = false;
        public void showVideoToPicture(byte[] buf)
        {
            try
               
            {
                if (doublebit == false)
                {
                    Common.showpicture(840, 540, 16, 60, this.pictureBoxVideo, buf);
                }
                else if (doublebit == true)
                {
                    MemoryStream ms = new MemoryStream(); //新建内存流
                    ms.Write(buf, 0, buf.Length); //赋值
                    this.pictureBoxVideo.SizeMode = PictureBoxSizeMode.StretchImage;
                    this.pictureBoxVideo.Image = Image.FromStream(ms); //读取流中内容
                    ms.Dispose();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }


        /// <summary>
        /// picture video  双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBoxVideo_DoubleClick(object sender, EventArgs e)
        {
            Rectangle rect = new Rectangle();

            rect = Screen.GetBounds(this);

            if (pictureBoxVideo.Dock != DockStyle.Fill)
            {
                doublebit = true;
                hidecontrol();//隐藏控件
                this.pictureBoxVideo.Dock = DockStyle.Fill;
                this.FormBorderStyle = FormBorderStyle.None;
                this.MaximumSize = new Size(rect.Width, rect.Height);
                //设置相应位置
                this.Location = new System.Drawing.Point(0, 0);

                //从左上角开始
                this.pictureBoxVideo.Location = new System.Drawing.Point(0, 0);

                this.Width = rect.Width;
                this.Height = rect.Height;

            }
            else
            {
                showcontrol();//显示控件
                this.pictureBoxVideo.Dock = DockStyle.None;
                this.FormBorderStyle = FormBorderStyle.Sizable;

                this.FormBorderStyle = FormBorderStyle.FixedDialog;//窗体 固定大小
                this.Width = 1100;
                this.Height = 750;
                doublebit = false;
            }
        }


        /// <summary>
        /// image至Tpicturebox显示
        /// </summary>
        /// <param name="buf"></param>
        public void showImageToPicture(byte[] buf)
        {
            this.pictureBoxImage.Width = 840;
            this.pictureBoxImage.Height = 540;
            this.pictureBoxImage.Location = new Point(16, 60);

            Common.showpicture(840, 540, 16, 60, this.pictureBoxImage, buf);

            if (planetAll != string.Empty)
            {
                string plantecolor = planetAll.Substring(0, 1);
                if (plantecolor != "蓝" && plantecolor != "黄" && plantecolor != "绿" && plantecolor != "黑" && plantecolor != "白")
                {
                    planetAll = "整牌据识";
                }
                string pic = "vimage" + DateTime.Now.ToString("HHmmss") + "(" + planetAll + ")" + ".jpg";
                Trace.WriteLogFile(pic);
                Common.SaveTriggerPicture(pic, buf);//保存图片至windows目录中
            }
        }

        /// <summary>
        /// 软触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TriggerButton_Click(object sender, EventArgs e)
        {
            try
            {
                //lpnr动态库
                if (ConfigHelper.GetConnectionStringConfig("haslpnr") == "yes")
                {
                    if (CameraHandle != IntPtr.Zero)
                    {
                        if (_isreleasedata == true)
                        {
                            _isreleasedata = false;
                            if (LPNRProgram.LPNR_SoftTrigger(CameraHandle))
                            {
                                softTriggerCount++;
                                Trace.WriteLogFile("完成" + softTriggerCount + "次软触发");
                            }
                        }
                    }
                    else
                    {
                        Trace.WriteLogFile("抓拍机未能正确初始化 句柄为0");
                    }
                }

                if (ConfigHelper.GetConnectionStringConfig("hasWJ") == "yes") //WJdll
                {
                    bool ForceRef = false;
                    ForceRef = LPNRProgram.WJLS_DVR_ForceCapture(WJ_Handle);
                    //万集 动态库
                    if (ForceRef)
                    {
                        Trace.WriteLogFile("WJ DLL 抓拍完成 " + ForceRef);
                    }
                }

             
            }

            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }

        /// <summary>
        ///关闭摄像机链接 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CloseButton_Click(object sender, EventArgs e)
        {
            CloseButton.Enabled = false;
            LinkButton.Enabled = true;
            bool _isclose = false;
            try
            {

                if (client != null)
                {
                    client.Close();
                }
                if (ConfigHelper.GetConnectionStringConfig("haslpnr") == "yes") //WJdll
                {
                    if (CameraHandle != IntPtr.Zero)
                    {
                        _isclose = LPNRProgram.LPNR_Terminate(CameraHandle);
                        if (_isclose == true)
                        {
                            CameraHandle = IntPtr.Zero;
                            Trace.WriteLogFile("关闭摄像机连接");
                        }
                    }
                    else
                    {
                        Trace.WriteLogFile("摄像机返回句柄为0");
                    }
                }

                if (ConfigHelper.GetConnectionStringConfig("hasWJ") == "yes") //WJdll
                {
                    bool wj_close = false;

                    wj_close = LPNRProgram.WJLS_DVR_Logout(WJ_Handle);

                    if (wj_close)
                    {
                        Trace.WriteLogFile("WJ 关闭摄像机连接");
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }





        /// <summary>
        /// 输入图像按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InputImagebutton_Click(object sender, EventArgs e)
        {
            this.pictureBoxVideo.Visible = false;
            this.HeadpictureBox.Visible = false;
            this.QuadpictureBox.Visible = false;
            this.pictureBoxImage.Visible = true;

        }
        /// <summary>
        /// 实时图像按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LiveVideobutton_Click(object sender, EventArgs e)
        {
            this.pictureBoxVideo.Visible = true;
            this.pictureBoxImage.Visible = false;
            this.HeadpictureBox.Visible = false;
            this.QuadpictureBox.Visible = false;
        }
        /// <summary>
        /// 车头图按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Headbutton_Click(object sender, EventArgs e)
        {
            this.pictureBoxVideo.Visible = false;
            this.HeadpictureBox.Visible = true;
            this.QuadpictureBox.Visible = false;
            this.pictureBoxImage.Visible = false;
        }
        /// <summary>
        /// 1/4图片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Quadbutton_Click(object sender, EventArgs e)
        {
            this.pictureBoxVideo.Visible = false;
            this.HeadpictureBox.Visible = false;
            this.QuadpictureBox.Visible = true;
            this.pictureBoxImage.Visible = false;
        }

        /// <summary>
        /// 对时间
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SetSyncTimebutton_Click(object sender, EventArgs e)
        {
            bool SynctimeBit = false;

            try
            {
                if (SynctimeBit == false)
                {
                    if (SynctimeBit = LPNRProgram.LPNR_SyncTime(CameraHandle))
                    {
                        Trace.WriteLogFile("更新抓拍机系统时间成功");
                    }
                }
            }
            catch (Exception ex)
            {

                throw new Exception("对时间失败" + ex.Message);
            }
        }


        /// <summary>
        /// 开启UDPserver
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UdpServerButton_Click(object sender, EventArgs e)
        {
            if (client != null)
            {
                client.Close();
            }

            //开启发送接收线程
            //client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            //EndPoint remoteip;
            //remoteip = new IPEndPoint(IPAddress.Parse("192.168.10.181"), 10040);
            //remoteip = new IPEndPoint(IPAddress.Any, 10040);
            //client.Bind(remoteip);

            //rece = new Thread(ReciveMsg);
            //rece.Start();

            //AsyncSocketUDPServer.startRec();
            //Udprece = new Thread(new ThreadStart(aus.ReceiveMsg));
            //Udprece.Start();

            udptest.StartUdpReceive();

            //AsyncSocketUDPClient au = new AsyncSocketUDPClient();
            //Udprece = new Thread(new ThreadStart(au.SendMsg));
            //Udprece.Start();
        }

        public byte[] MAGIC;
        /// <summary>
        /// 抬杆
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///

        private void Raise_Click(object sender, EventArgs e)
        {
            byte[] buf = { 0x34, 0x12, 0xcd, 0xab, 0x01, 0x00, 0x00, 0x00, 0x01, 0x90, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6E, 0x74, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x3D, 0x6D, 0x69, 0x75, 0x6B, 0x65 };
            udptest.StartUdpSend(buf);

            //byte[] MAGIC = new byte[4]{0x34, 0x12 ,0xcd ,0xab};
            //byte[] SN = new byte[4] { 0x01, 0x00, 0x00, 0x00 };
            //byte[] Code = new byte[]
            //MAGIC = new byte[] { 0x34, 0x12, 0xcd, 0xab, 0x01, 0x00, 0x00, 0x00, 0x01, 0x90, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6E, 0x74, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x3D, 0x6D, 0x69, 0x75, 0x6B, 0x65 };
        }

        /// <summary>
        /// 落杆
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Fall_Click(object sender, EventArgs e)
        {
            byte[] buf = { 0x34, 0x12, 0xcd, 0xab, 0x01, 0x00, 0x00, 0x00, 0x01, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6E, 0x74, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x3D, 0x6D, 0x69, 0x75, 0x6B, 0x65 };
            udptest.StartUdpSend(buf);
        }



        public void sendMsg()
        {
            try
            {
                Trace.WriteLogFile("发送线程开启");

                string vechIp = ConfigHelper.GetConnectionStringConfig("VechileIp");
                int udpport = 10041;
                EndPoint point = new IPEndPoint(IPAddress.Parse(vechIp), udpport);

                //client.SendTo(Encoding.UTF8.GetBytes(msg),point);
                if (_issendudp == true)
                {
                    client.SendTo(MAGIC, point);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        public void ReciveMsg()
        {
            try
            {
                Trace.WriteLogFile("接受线程开启");
                _issendudp = false;
                Trace.WriteLogFile(_isrecudp.ToString());
                while (_isrecudp == true)
                {
                    EndPoint point = new IPEndPoint(IPAddress.Any, 0);//用来保存发送方的ip和端口号
                    byte[] buffer = new byte[20];
                    int length = client.ReceiveFrom(buffer, ref point);//接收数据报
                    string message = Common.byteToHexStr(buffer);
                    //string message = Encoding.UTF8.GetString(buffer, 0, length);
                    Trace.WriteLogFile("收到UDP消息是" + message);
                }
                Trace.WriteLogFile("接受线程关闭");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }


        /// <summary>
        /// 隐藏控件
        /// </summary>
        public void hidecontrol()
        {
            //按钮
            this.LiveVideobutton.Visible = false;
            this.InputImagebutton.Visible = false;
            this.Headbutton.Visible = false;
            this.Quadbutton.Visible = false;

            this.TriggerButton.Visible = false;
            this.ParaButton.Visible = false;
            this.SetSyncTimebutton.Visible = false;

            //textbox
            this.GetTimingtext.Visible = false;
            this.LivecheckBox.Visible = false;
            this.PlateColorlabel.Visible = false;
            this.PlateBinarylabel.Visible = false;
            this.PlateLable.Visible = false;
            this.Confidencelabel.Visible = false;

            this.ColorpictureBox.Visible = false;
            this.BinarypictureBox.Visible = false;
            this.PlateText.Visible = false;
            this.confidenceText.Visible = false;
        }
        /// <summary>
        /// 显示控件
        /// </summary>
        public void showcontrol()
        {
            //按钮
            this.LiveVideobutton.Visible = true;
            this.InputImagebutton.Visible = true;
            this.Headbutton.Visible = true;
            this.Quadbutton.Visible = true;

            this.TriggerButton.Visible = true;
            this.ParaButton.Visible = true;
            this.SetSyncTimebutton.Visible = true;

            // textbox
            this.GetTimingtext.Visible = true;
            this.LivecheckBox.Visible = true;
            this.PlateColorlabel.Visible = true;
            this.PlateBinarylabel.Visible = true;
            this.PlateLable.Visible = true;
            this.Confidencelabel.Visible = true;

            this.ColorpictureBox.Visible = true;
            this.BinarypictureBox.Visible = true;
            this.PlateText.Visible = true;
            this.confidenceText.Visible = true;
        }


        private void LPNRTool_FormClosing(object sender, FormClosingEventArgs e)
        {
            //_isrecudp = false;
            //System.Threading.Thread.CurrentThread.Abort();
            //Application.ExitThread();
            if (Camera_One_CallBackThread != null)
            {
                Camera_One_CallBackThread.Abort();
            }
        }

        private void PlateText_TextChanged(object sender, EventArgs e)
        {

        }

        private void pictureBoxImage_Click(object sender, EventArgs e)
        {

        }

        private void pictureBoxVideo_Click(object sender, EventArgs e)
        {

        }

        private void pictureBoxImage_DoubleClick(object sender, EventArgs e)
        {

        }

        private void GetTimingtextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void TprIpcomboBox_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void QuadpictureBox_Click(object sender, EventArgs e)
        {

        }

        private void HeadpictureBox_Click(object sender, EventArgs e)
        {

        }

        private void ParaButton_Click(object sender, EventArgs e)
        {
            //child form 子窗口传递父窗体
            parachildform.Owner = this;
            parachildform.ShowDialog();//静态显示
        }

        private void colorpictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void ColoerRichTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void ColorpictureBox_Click(object sender, EventArgs e)
        {

        }

        private void BinarypictureBox_Click(object sender, EventArgs e)
        {

        }

        private void PlateLable_Click(object sender, EventArgs e)
        {

        }

        private void LivecheckBox_CheckedChanged(object sender, EventArgs e)
        {
        }

        private void confidenceText_TextChanged(object sender, EventArgs e)
        {

        }

        private void SystemTime_Tick(object sender, EventArgs e)
        {

        }

        private void anonymouscheckBox_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void textBox_TextChanged(object sender, EventArgs e)
        {

        }

    }
}
